package com.yuejian_06.yuejian_06.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.yuejian_06.yuejian_06.Listener.MeListener;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.bean.ActivityBean;
import com.yuejian_06.yuejian_06.bean.ContestBean;
import com.yuejian_06.yuejian_06.model.HomeModel;

public class ContestInfoActivity extends BaseActivity {
    private TextView contest_name,contest_date,contest_address,net,contest_content,sponsor;
    private ImageView contest_pic;
    private ImageButton back;

    @Override
    void initViews() {

    }

    @Override
    void initEvents() {

    }

    @Override
    void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contest_info);
        initView();//初始化事件
        Intent intent = getIntent();
        String contest_id1 = intent.getStringExtra("contest_id");
        HomeModel homeModel = new HomeModel();
        homeModel.getContestInfo(contest_id1,meListener);
    }

    private  void initView(){
        contest_name = (TextView) findViewById(R.id.contest_name);
        contest_date = (TextView) findViewById(R.id.contest_date);
        contest_address = (TextView) findViewById(R.id.contest_address);
        net = (TextView) findViewById(R.id.net);
        contest_content = (TextView) findViewById(R.id.contest_content);
        sponsor = (TextView) findViewById(R.id.sponsor);
        contest_pic = (ImageView) findViewById(R.id.contest_pic);
        back = (ImageButton) findViewById(R.id.back);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    private MeListener<ContestBean> meListener =new MeListener<ContestBean>() {
        @Override
        public void onResponse(ContestBean o) {
            ContestBean res=o;
            contest_name.setText(res.getContest_name());
            sponsor.setText("活动主办方："+res.getSponsor());
            net.setText("活动网址："+res.getNet());
            contest_date.setText("比赛日期："+res.getContest_date());
            contest_address.setText("比赛地址："+res.getContest_address());
            contest_content.setText("    "+res.getContest_content());
            if (!"".equals(res.getContest_pic()))
                Picasso.with(ContestInfoActivity.this).load("http://10.0.2.2/yuejian/Public/acpics/"+res.getContest_pic()).into(contest_pic);
        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(ContestInfoActivity.this,"比赛详情失败",Toast.LENGTH_SHORT).show();
        }
    };
}
